//
//  LED_FILE.c
//  ARDUINO_PROPELLER
//
//  Created by FRANCIS PAPINEAU on 12-02-06.
//  Copyright 2012 carleton university. All rights reserved.
//


#include <stdio.h>

//! ------------------------------------------------------------------------------

//! This function will send out the digital bits, to select the
//! right analog output in order to get the right ADC value.
//! Then this function will read the values of the voltages and
//! will add those values to the sending buffer with the proper 
//! string format. Once this is accomplished the Digital pins
//! are set to 0 to reset the ouputs.

//! ------------------------------------------------------------------------------

bool setDigitalSelectBits(int LEDPinValue){
    
    //! this function will send the approriate bits to the mux in order, to
    //! acquire the right voltage readings. It takes in the selected DigitalPin.
    
    //! case:
    //! 1 - PWR -> 001
    //! 2 - Standby -> 010
    //! 3 - ERROR -> 011
    //! 4 - ALL OFF -> 100
    //! 5 - Debug -> 101
    
    
    switch (LEDPinValue) {
        case 1: //! PWR
            
            digitalWrite(LEDPWR, HIGH);
            
            if((digitalRead(LEDPWR) == HIGH){
                checkVar = true;
            }else {
                checkVar = false;
            }
               break;
        case 2: //! Standby
               
            digitalWrite(LEDStandby, HIGH);
               
            if((digitalRead(LEDStandby) == HIGH){
                checkVar = true;
            }else {
                checkVar = false;
            }               
            break;
        case 3: //! ERROR
            digitalWrite(LEDError, HIGH);
                  
            if((digitalRead(LEDError) == HIGH){
                checkVar = true;
            }else {
                checkVar = false;
            }
            break;
        case 4: //! ALL OFF
                                          
            digitalWrite(LEDPWR, LOW);
            digitalWrite(LEDStandby, LOW);
            digitalWrite(LEDError, LOW);
            digitalWrite(LEDDEBUG, LOW);
            digitalWrite(LEDRUN, LOW);
               
            if(digitalRead(LEDPWR) == LOW && digitalRead(LEDStandby) == LOW &&
                  digitalRead(LEDError) == LOW && digitalRead(LEDDEBUG) == LOW
                    && digitalRead(LEDRUN) == LOW){
                checkVar = true;
            }else {
                checkVar = false;
            }
            break;
                        
        case 5: //! Debug
            digitalWrite(LEDRUN, HIGH);
            if((digitalRead(LEDRUN) == HIGH){
                checkVar = true;
            }else {
                checkVar = false;
            }
            break;
               
         case 6: //! RUN
            digitalWrite(LEDDEBUG, HIGH);
            if((digitalRead(LEDDEBUG) == HIGH){
                checkVar = true;
            }else {
                checkVar = false;
            }
            break;
               
        case 7: //! ALL ON
            digitalWrite(LEDPWR, HIGH);
            digitalWrite(LEDStandby, HIGH);
            digitalWrite(LEDError, HIGH);
            digitalWrite(LEDDEBUG, HIGH);
            digitalWrite(LEDRUN, HIGH);
               
            if(digitalRead(LEDPWR) == HIGH && digitalRead(LEDStandby) == HIGH &&
                digitalRead(LEDError) == HIGH && digitalRead(LEDDEBUG) == HIGH
                  && digitalRead(LEDRUN) == HIGH){
                   checkVar = true;
            }else {
                   checkVar = false;
            }
            break;
        default:
               break;
               }
        if(checkVar){
               return true;
        }else{
               sendError(checkVar, SelectBitAddress);
               return false;
        }
}
                           
